//
// Created by Semir on 2020/5/12.
//

#include <iostream>

using namespace std;

struct ListNode {
    int val;
    struct ListNode *next;
    explicit ListNode(int x) : val(x), next(nullptr) {}
};

ListNode* linkList(int *arr, int length) {
    auto* pHead = new ListNode(arr[0]);
    auto* cNode = pHead;
    for (int i = 1; i < length; i++) {
        cNode->next = new ListNode(arr[i]);
        cNode = cNode->next;
    }
    return pHead;
}

ListNode* ReverseList(ListNode* pHead) {
    if (pHead == nullptr) {
        return nullptr;
    }
    ListNode* pNode = pHead;
    auto* dNode = new ListNode(-1);
    while (pNode) {
        auto* node = new ListNode(pNode->val);
        node->next = dNode->next;
        dNode->next = node;
        pNode = pNode->next;
    }
    return dNode->next;
}

int main() {
    int arr[5] = {1,2,3,4,56};
    ListNode* pHead = linkList(arr, 5);
    ListNode* nHead = ReverseList(pHead);
    cout << nHead << endl;
    return 0;
}